#ifndef BUAAPAIREPROGRAMMING_GRAPH_H
#define BUAAPAIREPROGRAMMING_GRAPH_H

#include <vector>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <queue>


using namespace std;

class Node {
private:
    char *body;
    int head, tail;
    int len;
    int ind;
    int origin_ind;
    int oud;
    int id;
    int pre;
    bool used;
    bool disabled;
    int to[10000];
public:

    Node(char *input, int id) {
        body = input;
        len = strlen(input);
        head = input[0];
        tail = input[len - 1];
        ind = 0;
        origin_ind = 0;
        oud = 0;
        pre = -1;
        this->id = id;
        used = false;
        disabled = false;
        //to = vector<int>();
    }

    int get_id() {
        return id;
    }

    int get_head() {
        return head;
    }

    int get_tail() {
        return tail;
    }

    int get_len() {
        return len;
    }

    int get_ind() {
        return ind;
    }

    int ind_inc() {
        ind = ind + 1;
        origin_ind = origin_ind + 1;
        return ind;
    }

    void reset_ind() {
        ind = origin_ind;
    }

    int ind_dec() {
        ind = ind - 1;
        return ind;
    }

    int get_to(int i) {
        return to[i];
    }

    int get_oud() {
        return oud;
    }


    int oud_inc() {
        oud = oud + 1;
        return oud;
    }

    void add(int u) {
//        vector<int> sb;
//        sb.push_back(u);
//        cout << sb.size() << endl;
        //cout << "here";
        to[oud] = u;
        oud_inc();
    }

    string get_body() {
        string str(this->body);
        return str;
    }

    bool is_used() {
        return used;
    }

    void set_used(bool b) {
        used = b;
    }

    void set_disabled(bool b) {
        disabled = b;
    }

    bool is_disabled() {
        return disabled;
    }

    int get_pre() {
        return pre;
    }

    void set_pre(int p) {
        pre = p;
    }
};

Node *create_graph(char *words[], int len);

int topo_sort(Node *nodes, int len, int *topo_list);


#endif //BUAAPAIREPROGRAMMING_GRAPH_H